//
//  CPBasicTabbarController.swift
//  cockpit
//
//  Created by Haijun Si on 2020/7/8.
//  Copyright © 2020 chenganrt. All rights reserved.
//

import UIKit

class CPBasicTabbarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 修改标签栏选中时文字颜色、字体
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red, NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 18.0)], for: .selected)
       // 修改标签栏未选中时文字颜色、字体
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.orange, NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 18.0)], for: .normal)
       // 设置字体偏移
       //UITabBarItem.appearance().titlePositionAdjustment = UIOffsetMake(0.0, 0.0)

        addChildVC(childVC: CPHomeViewController(), tile1: "首页", image1: "home")
        addChildVC(childVC: CPWaitDoViewController(), tile1: "待办", image1: "waitDo")
        addChildVC(childVC: CPMessageViewController(), tile1: "消息", image1: "message")
        addChildVC(childVC: CPMineViewController(), tile1: "我的", image1: "mine")
    }
    
    func addChildVC(childVC:UIViewController,tile1:String,image1:String) -> Void {
        childVC.title = tile1
        
        var img = UIImage(named: image1 + "_n")
        img = img?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)
        
        var selectedImg = UIImage(named: image1 + "_s")
        selectedImg = selectedImg?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)
        
        childVC.tabBarItem.image = img
        childVC.tabBarItem.selectedImage = selectedImg
        
        let nav = CPBaseNavigationController(rootViewController: childVC)
        addChild(nav)
    }
}
